/*
 * kylin-os-manager
 *
 * Copyright (C) 2022, KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "kwidget.h"
#include "knavigationbar.h"
#include "kymanager_plugin.h"
#include "utils.h"

#include <QModelIndex>
#include <QStandardItem>
#include <QStandardItemModel>
#include <QLabel>
#include <QObject>
#include <QStackedWidget>

using namespace kdk;


class MainWindow : public KWidget
{
    Q_OBJECT

public:
    MainWindow(QVector<KyManagerPluginProvider *> plugins, QWidget *parent = nullptr);
    ~MainWindow();
    void setSingleFileFd(int fd)
    {
        this->mSingleInstanceFd = fd;
    }

protected:
	void keyPressEvent(QKeyEvent *event) override;

private:
    KNavigationBar *mNaviBar = nullptr;
    QLabel *mLabel = nullptr;
    // QPushButton* mLoginBtn = nullptr;
    QLabel *mLoginLabel = nullptr;
    QLabel *mLoginStatus = nullptr;
    QLabel *mLoginTips = nullptr;
    QStackedWidget *mStackWidget = nullptr;

    QVector<KyManagerPluginProvider *> m_plugins;
    QMap<QString, int> mMapPlugin;
    QMap<QString, KyManagerPlugin *> mMapPluginIndex;
    QMap<QString, pluginconfig_t> mLoadPluginMap;
    QVector<QString> mNeedLoadVector;

    int mSingleInstanceFd = 0; //这个是首页的单例锁句柄

    bool initPluginsInfo(); //用来准备要加载的插件信息
    void initNavigationArea();
    void initMainWorkArea();
    void initConnectSig();
    void addKyManagerPluginSort(KyManagerPlugin *);
    void setStackWidget(QString name);
    void setFirstWidget();
    void slotCloseBtnIsClicked();

public slots:
    void slotNaviClicked(const QModelIndex &index);
};
#endif // MAINWINDOW_H
